//: [Previous](@previous)

import Foundation


var arr = [15,8,2,3,6,9]
arr.sorted(by: > )

func reverse(num: Int) -> Int {
    var temp = num
    var new = 0
    while temp != 0 {
        //取出最后一个数字
        let lastNum = temp%10
        temp /= 10
        new = new * 10 + lastNum
    }
    return new
}
//reverse(num: 61234)


func reverseNum(num: inout Int) -> Int {
    var newNum = 0
    var step = 0
    let temp = num
    while num > 10 {
        let lastNum = num%10
        num = num/10
        step += 1
        print(num,lastNum)
    }
    num = temp
    print("次数：\(step)")
    for i in 1...step {
        let lastNum = num % 10
        num = num/10
        newNum += lastNum * Int(pow(10, Double(step + 1 - i)))
        if i == step {
            newNum += num
        }
        print(lastNum, num , newNum)
    }
    print(newNum)
    return newNum
}
var num = 61234
//reverseNum(num: &num)


// filter的使用
func filter_1(array: Array<Int>) -> Array<Int> {
    array.filter { num in
        return num % 2 == 0
    }
}

var array = [1,2,3,4,5,6,7,8,9,10]
var array2 = [1,3,5]
filter_1(array: array)

func filterArray(arr: Array<Int>, from arr2: Array<Int>) -> Array<Int> {
    
    arr.filter { num in
        return !arr2.contains(num)
    }
}
//filterArray(arr: array, from: array2)


// 区分static和class关键字
//demo_class_static()

/**
 * extension
 * 1. 类  /结构体 /枚举 都可以使用extension
 * 2. extension中不能重写本类的方法
 * 3. extension中编写的数据包含在类信息中, 编译时就已确定
 * 4. 可以使类遵循协议
 */
//demo_extension()


// 函数式编程,柯里化
//demo_curriedTest()


// 函数相关
//funcDemo_printMathResult()
//funcDemo_useFuncAsRes()


// 闭包相关
//closureDemo_sort()
//demo_closure()
//closureExample_2()
//closureExample_5()
//closureExample_6()
//closureExample_7()
//closureExample_8()
//closureExample_9_autoclosure()


// 类和结构体
//classAndStructDemo()


// 属性
//propertyDemo_1()
//propertyDemo_4()
//propertyDemo_5()


// 构造过程
//initialzieDemo_1()
//initialzieDemo_2()


// 自动引用计数
//arcDemo_1()
//arcDemo_2()



// 数据竞争问题
zDemo_dataRace()

String_Practice.isPalindrome("abcdcba")
